package com.hellohoper.test.mybatis.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hellohoper.assembly.common.utils.base.model.PageModel;
import com.hellohoper.test.mybatis.mapper.CityDistanceMapper;
import com.hellohoper.test.mybatis.mapper.model.CityDistance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by hk on 12/12/16.
 */
@Service
public class CityDistanceService {

    @Autowired
    private CityDistanceMapper cityDistanceMapper;

    public int deleteByPrimaryKey(Long id) {
        return cityDistanceMapper.deleteByPrimaryKey(id);
    }

    public PageModel selectPageList(int pageNum, int pageSize, CityDistance record) {
        Page<Object> page = PageHelper.startPage(pageNum, pageSize, true);
        List<CityDistance> cityDistanceList = cityDistanceMapper.selectPageList(record);
        return new PageModel<>(pageNum, pageSize, page.getTotal(), cityDistanceList);
    }

    @Transactional
    public int insert(CityDistance record) {
        int insert = cityDistanceMapper.insert(record);
        return insert;
    }

    @Transactional
    public int insertSelective(CityDistance record) {
        int insert = cityDistanceMapper.insert(record);
//        int a = 1 / 0;
        return insert;
    }

    public CityDistance selectByPrimaryKey(Long id) {
        return cityDistanceMapper.selectByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(CityDistance record) {
        return cityDistanceMapper.updateByPrimaryKeySelective(record);
    }

    public int updateByPrimaryKey(CityDistance record) {
        return cityDistanceMapper.updateByPrimaryKey(record);
    }
}
